/**
 * 转换列表
 * audit_statu:{1: "未审核", 2: "通过", 3: "未通过"}
 * change_type: {1: "普通转专业", 2: "专业转普通"}
 * Created by KY on 2017/6/23.
 */
define(['ldfw/core','art',
    'text!tpl/transform/list.tpl',
    'text!tpl/transform/row.tpl',
    'comps/ajax',
    'ldfw/helper/formatHelper'],
function (LDFW,artTemplate, tpl, rowTpl, ajax) {
    var View = LDFW.Container.extend({
        tpl: tpl,
        className:'panel',
        initialize: function () {
            this.on('shown', this.loadData)
        },
        events:{
            'click [operate="cancel"]':'cancel'
        },
        loadData: function () {
            const _this = this
            ajax.post('cpliL.3.7',{audit_type:2}).success(function (resp) {
                _this.renderContent(resp.result)
            })
        },
        renderContent: function (transformList) {
            let addTransform = true
            if(!_.isEmpty(transformList)){
                transformList.forEach(function(transform){
                    if((transform.audit_status==3 && transform.change_type==1)||transform.audit_status == 1){
                        addTransform = false
                    }
                })
                let html = artTemplate.compile(rowTpl)(transformList)
                this.$el.find('.detail-panel_body').html(html)
            }
            if(addTransform){
               $('#addTransform').show()
            }
        },
        cancel:function(event){
            const _this = this
            $.confirm({text:'确认要撤销转化申请吗？',onOK:function(){
                let audit_no = $(event.target).attr('auditno')
                ajax.post('cpliL.3.109',{audit_no:audit_no})
                    .success(function(resp){
                        _this.$el.find('#transform-form_'+audit_no).empty().html(artTemplate.compile(rowTpl)(resp.result))
                    })
            }})
        }
    })
    return new View()
})